package com.vince.hulk.mechanism
{
import com.vince.hulk.character.Character;

import org.flixel.FlxSprite;

/**
 * author yangwz
 */		
public class Switch extends FlxSprite implements IMechanism
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	/**
	 * Constructs a new <code>Switch</code> instance.
	 * 
	 */
	public function Switch(X:Number=0, Y:Number=0, imech:IMechanism = null)
	{
		super(X, Y, null);
		loadGraphic(img, true, true, 16, 25);
		addAnimation("active", [1], 1, false);
		addAnimation("non_active", [0], 1, false);
		isActivated = false;
		mech = imech;
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	[Embed(source = "assets/Switch.png")]
	private var img:Class;
	
	private var isActivated:Boolean;
	
	private var mech:IMechanism;
	//==========================================================================
	//  Methods
	//==========================================================================
	public function activate(character:Character) : void
	{
		if (!isActivated)
		{
			isActivated = true;
		}
		else
		{
			isActivated = false;
		}
		mech.activate(character);
	}
	
	public function toggle():void
	{
	}
	
	override public function update() : void
	{
		if (isActivated)
		{
			play("active");
		}
		else
		{
			play("non_active");
		}
	}
}
}